#include <QtGui/QApplication>

#include "Mouse3DInput.h"

#include "mainwindow.h"

MainWindow* w;

#include <signal.h>

void fnExit1 (int)
{
    //only way to get control on console window close
  w->Shutdown();
  puts ("Unexpected exit. Exit function 1. Starting graceful shutdown...\n");
  Sleep(5000);
  /*
    NationalInstruments m;
    //m = new NationalInstruments();
    m.Initialize();
    m.StartResonantScanning();
    m.CloseShutter(0);
    Sleep(1000);
    m.StopResonantScanning();
    m.Shutdown();
    */

}


int main(int argc, char *argv[])
{
    signal(SIGINT, fnExit1);
    signal(SIGTERM, fnExit1);
    signal(SIGBREAK, fnExit1);
    signal(SIGABRT, fnExit1);
    signal(SIGABRT_COMPAT, fnExit1);

    QApplication a(argc, argv);
    a.setStyle("cleanlooks");
    w = 0;
    w = new MainWindow();
    QObject::connect(&a, SIGNAL(focusChanged(QWidget*, QWidget*)), w, SLOT(fnChangeFocus(QWidget*, QWidget*)));

    //MainWindow w;
    //atexit(fnExit1);


    //this is where the 3d mouse is created
    //i think this needs to happen before w.show(), ie signals set before display

    //Mouse3DInput mouse(&w);
    //w.m3dConnexion = &mouse;

    //QObject::connect(&mouse, SIGNAL(Move3d(std::vector<float>&)), &w, SLOT(OnMove(std::vector<float>&)));
    w->show();

    //Sleep(1000);
    w->Initialize();

    int code = 0;
    code =  a.exec();
    return code;
}


